<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<#include "/include/head_common.ftl">
	<#include "/include/login_trace.ftl">
	<#assign permissionSet = fm.getPermission() />
	<#assign edit= fm.hasPermission("sql:define:edit",permissionSet)/>
<title>SQL管理</title>
    <script type="text/javascript">
        function page(n, s) {
            $("#pageNum").val(n);
            $("#pageSize").val(s);
            $("#searchForm")[0].submit();
            return false;
        }
		function clearDescribeQuery(){
			$("#sqlDescribe").val('');
			$("#searchForm")[0].submit();
		}
    </script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${rootUrl}/sql/define/list">SQL列表</a></li>
		<#if edit >
			<li><a href="${rootUrl}/sql/define/edit">SQL添加</a></li>
		</#if>
		<#if fm.hasPermission("sql:parameter:view",permissionSet) >
			<li><a href="${rootUrl}/sql/parameter/list">SQL参数列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:parameter:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/parameter/edit">SQL参数添加</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:view",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/list">列转换器列表</a></li>
		</#if>
		<#if fm.hasPermission("sql:fieldTransform:edit",permissionSet) >
			<li><a href="${rootUrl}/sql/fieldTransform/edit">列转换器添加</a></li>
		</#if>
	</ul>
	<form id="searchForm" action="${rootUrl}/sql/define/list"
		  method="post" class="breadcrumb form-search">
		<input id="pageNum" name="pageNum" type="hidden" value="${page.pageNum}" />
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />
		<label>数据源：</label>
		<select name="dataSource" class="input-small" style="text-align: center">
			<option value="">请选择...</option>
			<#list datasourceList as datasource>
				<option value="${datasource.name}"  <#if define.dataSource?? && datasource.name = define.dataSource> selected </#if> >${datasource.name}</option>
			</#list>
		</select>&nbsp;
		<label>描述：</label>
		<input class="input-medium" type="text" id="sqlDescribe" name="sqlDescribe" value="${define.sqlDescribe!''}"/>&nbsp;
		<input class="btn btn-primary" type="submit" value="查询" />
		&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" class="btn btn-primary" onclick="clearDescribeQuery()" value="清除描述查询" />
	</form>
	<#include "/include/message.ftl">
	<table id="contentTable"
		class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>数据源</th>
				<th>定义key</th>
				<th>描述</th>
<#--				<th>下划线转驼峰</th>-->
				<th>操作</th>
				<th>测试</th>
			</tr>
		</thead>
		<tbody>
			<#list page.list as define>
			<tr>
				<td><a href="${rootUrl}/sql/define/list?dataSource=${define.dataSource!''}">${define.dataSource!'' ?trim = ''? string('默认',define.dataSource!'')}</a></td>
				<td><a href="${rootUrl}/sql/define/edit?id=${define.id}">${define.defineKey!''}</a></td>
				<td>${define.sqlDescribe!''}</td>
<#--				<td>${define.underLineToCamel?string('是','否')}</td>-->
				<td>
					<#if edit>
						<a href="${rootUrl}/sql/define/edit?id=${define.id!''}">修改</a>
					    <a href="${rootUrl}/sql/define/delete?id=${define.id!''}" onclick="return confirmx('确认要删除该SQL吗？', this.href)">删除</a>
						<a href="${rootUrl}/sql/parameter/list?defineKey=${define.defineKey!''}">参数</a>
						<a href="${rootUrl}/sql/parameter/edit?defineKey=${define.defineKey!''}">添加参数</a>
						<a href="${rootUrl}/sql/fieldTransform/list?defineKey=${define.defineKey!''}">转换</a>
						<a href="${rootUrl}/sql/fieldTransform/edit?defineKey=${define.defineKey!''}">转换添加</a>
						<a href="${rootUrl}/sql/parameter/pageParam?defineKey=${define.defineKey!''}">添加分页参数</a>
					<#else>
						<a href="${rootUrl}/sql/define/edit?id=${define.id!''}">查看</a>
					</#if>
				</td>
				<td>
					<a href="${rootUrl}/sql/query?defineKey=${define.defineKey!''}" target="_blank">查询测试</a>
					<a target="_blank">参数调试</a>
					<a target="_blank">脚本调试</a>
				</td>
			</tr>
			</#list>
		</tbody>
	</table>
	<div class="pagination">
		<#assign funName = 'page' />
		<#assign ftPage = page>
		<#include "/include/page.ftl">
	</div>
</body>
</html>